// Class TMenu

#define MF_POPUP 0x10

//----------------------------------------------------------------------------//

function TMenu()

   static oClass

   if oClass == nil
      oClass = TClass():New( "TMENU" )

      oClass:AddData( "hMenu" )           // DATA hMenu
      oClass:AddData( "aItems" )

      oClass:AddClassData( "aPopups" )    // CLASSDATA aPopups

      oClass:AddMethod( "New", @New() )   // METHOD New()
      oClass:AddMethod( "Add", @Add() )

      oClass:Create()
   endif

return oClass:Instance()                  // creates the new object

//----------------------------------------------------------------------------//

static function New( lPopup )

   local Self := QSelf()

   lPopup = If( lPopup == nil, .f., lPopup )

   ::hMenu = If( ! lPopup, CreateMenu(), CreatePopup() )
   ::aItems = {}

   if ::aPopups == nil
      ::aPopups = {}
   endif

   if lPopup
      AAdd( ::aPopups, Self )
   endif

return Self

//----------------------------------------------------------------------------//

static function Add( oMenuItem )

   local Self := QSelf()

   AAdd( ::aItems, oMenuItem )

   if oMenuItem:bAction != nil .and. oMenuItem:bAction:ClassName() == "TMENU"
      AppendMenu( ::hMenu, MF_POPUP,;
                  oMenuItem:bAction:hMenu, oMenuItem:cPrompt )
   else
      AppendMenu( ::hMenu, 0, 110, oMenuItem:cPrompt )
   endif

return nil

//----------------------------------------------------------------------------//
